/*
 * Copyright 2013-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.normaltest.che300escjl.controller;

import com.normaltest.che300escjl.dto.Car;
import com.normaltest.che300escjl.utils.Elasticserch;
import com.normaltest.che300escjl.utils.TabsExcelUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

/**
 * @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
 */
@Controller
public class BasicController {

    // http://127.0.0.1:8080/hello?name=lisi
    @RequestMapping("/test")
    @ResponseBody
    public String hello(@RequestParam String s) throws IOException {
        //数据插入 Elasticserch.addCarsToIndex(Objects.requireNonNull(TabsExcelUtil.inExcel("B")));
        //Elasticserch.getToSearch(new Car("奥迪", "奥迪Q7(进口) 2012款 奥迪Q7(进口) 3.0 TFSI quattro(245kW)舒适型"));
        List<Car> a = TabsExcelUtil.inExcel("A");  //表a 转换成list
        HashMap<Car, Car> carCarHashMap = new HashMap<>();
        for (Car car : a) {
            Car bcar = Elasticserch.getToSearch(car);
            if (bcar != null) {
                carCarHashMap.put(car, bcar);
            }
        }
        TabsExcelUtil.bind(carCarHashMap);
        return "Hello " + s;
    }
    @RequestMapping("/yingshe")
    @ResponseBody
    public String yingshe(@RequestParam String s) throws IOException {
        Car fenci = TabsExcelUtil.fenci(s);
        Car toSearch = Elasticserch.getToSearch(fenci);
        return toSearch.getZiduan1()+" "+toSearch.getZiduan2();
    }
}
